/*
 * Copyright (c) 2008-2016 Haulmont.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.jmix.security;

/**
 * Class is responsible for the brute-force protection on user authentication.
 */
public interface BruteForceProtection {
    /**
     * Returns a number of login attempts left for the specified pair of login and IP-address.
     *
     * @param username     username.
     * @param ipAddress user IP-address.
     * @return true if count of login attempts left.
     */
    boolean isBlocked(String username, String ipAddress);

    /**
     * Registers unsuccessful login attempt.
     *
     */
    void registerLoginFailed(String username, String ipAddress);

    /**
     * @return true if brute-force protection is enabled in application settings.
     */
    boolean isProtectionEnabled();

    /**
     * Registers successful login attempt. Clear attempts count for user.
     *
     * @param username     username.
     * @param ipAddress user IP-address.
     */
    void registerLoginSucceeded(String username, String ipAddress);
}
